<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
	<jsp:include page="/include.jsp"/>
	<script type="text/javascript">
	 $(document).ready(function(){
		 doQuery();
	 });
	//分页查询
	function doQuery()
	{
		$('#framework_moudle_table').datagrid({
			url :'${pageContext.request.contextPath}/systemManagerAction!getEtlMoudleData.action',
			queryParams:serializeObject($('#framework_moudle_table_form')),
			fit:true,
			border:false,
			fitColumns:true,
			pagination:true,
			striped:true,
			pageList:[10,15,20],
			rownumbers:true,
			singleSelect:false,
			pagePosition:'bottom',
			autoRowHeight:true,
			rownumbers:false,
			sortName:'moudleid',
			columns:[[  {field:'moudleid',checkbox:false,hidden:true},
						{field:'moudlename',title:'模块名称',width:80,align:'left',sortable:true},
						{field:'descinfo',title:'模块描述',width:150,align:'left',formatter:function(value,rowData,rowIndex){
							if(rowData.descinfo!=undefined){
 								return '<div style="width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;" title="'+rowData.descinfo+'">'+rowData.descinfo+'</div>';
 							}
						}},
						{field:'dsafd',title:'操作',width:50,align:'left',formatter:function(value,rowData,rowIndex){
							return  '<span  style="cursor:pointer" onclick="doEdit(\''+rowData.moudleid+'\',\''+rowData.moudlename+'\',\''+trimStr(rowData.descinfo)+'\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改" style="margin-top:2px;"/>修改&nbsp;&nbsp;</span>'		
				                   +'<span  style="cursor:pointer" onclick="doDelete(\''+rowData.moudleid+'\')"><img  src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;"/>删除&nbsp;&nbsp;</span>';
						}}
					]],
			toolbar:'#framework_moudle_table_toobar'
		});
	}
	//去掉字符串空格
	function trimStr(str){
		var temp="";
		if(""!=str && null!=str){
			temp=str.replace(/\s+/g, "");
		}
		return temp;
	}
	//修改用户模块
	function doEdit(moudleid,moudlename,descinfo){
		$("#framework_modify_moudleid").val("");
		$("#framework_modify_moudledesc").val("");
		
		$("#framework_modify_moudleid").val(moudleid);
		$("#framework_modify_moudlename").val(moudlename);
		if(""!=descinfo && 'undefined'!=descinfo){
			$("#framework_modify_moudledesc").val(descinfo);
		}
		$("#framework_moudle_modify").show();
		//增加隔行变色效果
 	    $(".listtable").zebra();
		$('#framework_moudle_modify').dialog({
			modal : true,
			width:400,
			title : '修改模块',
			buttons : [ {
				text : '保存',
				iconCls : '',
				handler : function() {
					if ($("#framework_moudle_modify_form").form("validate"))
					{
						$.ajax({
							 url : '${pageContext.request.contextPath}/systemManagerAction!validMoudleName.action',
							 data:{moudlename:$("#framework_modify_moudlename").val(), moudleid:$("#framework_modify_moudleid").val(),operateType:'edit'},
							 dataType :'json',
							 cache : true,
							 beforeSend:function(){
								 $.messager.progress({title : '提示',text : '正在保存，请稍候 ....'});
							 },
							 success : function(r){ 
								 if (r.returnFlag) {
									 $.messager.show({title : '提示',msg : '该模块名称已存在'});
									 $.messager.progress('close'); 
							     }else{
							    	 $('#framework_moudle_modify_form').form('submit', {
											url :'${pageContext.request.contextPath}/systemManagerAction!modifyMoudleData.action',
											success : function(result) {
												try {
													var r = $.parseJSON(result);
													$.messager.show({
														title : '提示',
														msg : r.returnMsg
													});
													if (r.returnFlag) {
														$.messager.progress('close'); 
														$("#framework_moudle_modify").dialog('close');
													}
												} catch (e) {
													$.messager.alert('提示', result);
													$.messager.progress('close'); 
													$("#framework_moudle_modify").dialog('close');
												}
											}
										});
							     }
							 }
						 });
					}
					
				}
			}],
			onClose : function() {
				$("#framework_moudle_modify").hide();
				$('#framework_moudle_table').datagrid('reload');
			}
		});
	}
	//新增系统模块
	function doAdd(){
		$("#framework_moudlename").val("");
		$("#framework_add_moudledesc").val("");
		 $("#framework_moudle_add_validmoudlename").html(""); 
		$('#framework_moudle_add').show();
		 //增加隔行变色效果
  	     $(".listtable").zebra();
		$('#framework_moudle_add').dialog({
			modal : true,
			width:400,
			title : '新增模块',
			buttons : [ {
				text : '保存',
				iconCls : '',
				handler : function() {
					if ($("#framework_moudle_addform").form("validate"))
					{
						var moudlename=$("#framework_moudlename").val();
						$.ajax({
							 url : '${pageContext.request.contextPath}/systemManagerAction!validMoudleName.action',
							 data:{"moudlename":moudlename},
							 dataType :'json',
							 cache : true,
							 beforeSend:function(){
								 $.messager.progress({title : '提示',text : '正在保存，请稍候 ....'});
							 },
							 success : function(r){ 
								 if (r.returnFlag) {
									 $.messager.show({title : '提示',msg : '该模块名称已存在'});
									 $.messager.progress('close'); 
							     }else{
							    	 $('#framework_moudle_addform').form('submit', {
											url :'${pageContext.request.contextPath}/systemManagerAction!addMoudleData.action',
											success : function(result) {
												try {
													var r = $.parseJSON(result);
													$.messager.show({
														title : '提示',
														msg : r.returnMsg
													});
													$.messager.progress('close'); 
													if (r.returnFlag) {
														$("#framework_moudle_add").dialog('close');
													}
												} catch (e) {
													$.messager.show({title : '提示',msg : result});
													$.messager.progress('close'); 
													$("#framework_moudle_add").dialog('close');
												}
											}
										});
							     }
							 }
						 });
					}
				}
			}],
			onClose : function() {
				$("#framework_moudle_add").hide();
				$('#framework_moudle_table').datagrid('reload');
			}
		});
	}
	//单独删除
	function doDelete(moudleid){
		 $.ajax({
			 url : '${pageContext.request.contextPath}/systemManagerAction!ValidMoudleContainRole.action',
			 data:{"moudleid":moudleid},
			 dataType :'json',
			 cache : true,
			 success : function(r){ 
				 if (r.returnFlag) {
					 $.messager.show({
							title : '提示',
							msg : r.returnMsg
					 });
				 }else{
					 $.messager.confirm('删除确认', '确定要删除该条记录吗？',function(r){
							if(r){
								$('#framework_moudle_table_form').form('submit',{
									url:'${pageContext.request.contextPath}/systemManagerAction!deleteBatchMoudle.action?batchFlag=false&pid='+moudleid,
								    success:function(result){
									   try {
											var r = $.parseJSON(result);
											$.messager.show({
												title : '提示',
												msg : r.returnMsg
											});
											if (r.returnFlag) {
												$('#framework_moudle_table').datagrid('reload');
											}
										} catch (e) {
											$.messager.alert('提示', result);
										}
								    } 
						       });
							}
						});
				 }
				
			 }
	     });
	}
	
	</script>
</head>

<body class="easyui-layout">
    <form id="framework_moudle_table_form" method="post">
		<div data-options="region:'center'" style="border-top:none">
			<table id="framework_moudle_table"></table>
			<div id="framework_moudle_table_toobar" class="etl_panel_title">
				<a href="javascript:void(0);" onclick="doAdd()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left">新增模块</a>
				<div class="datagrid-btn-separator"></div>
				<a href="javascript:void(0);"  class="easyui-linkbutton"  data-options="iconCls:'',plain:true"></a>
				<!-- <a href="javascript:void(0);" onclick="doBatchDelete()" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">批量删除</a> -->
			</div>
		</div>
    </form>
    <!-- 新增用户模块 -->
	<div id="framework_moudle_add" style="display: none">
	   <form id="framework_moudle_addform" method="post">
	     <table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" class="listtable">
			<tr>
				<td height="40px" style="text-align:right"><span style="color:red;font-size:15px">*</span>模块名称：&nbsp;</td>
				<td height="40px">
					<input id="framework_moudlename"  type="text" name="moudlename" class="easyui-validatebox" data-options="required:true,missingMessage:'模块名称必须填写',validType:['specialCharFilter', 'length[1,30]']" panelHeight="auto"/>
				</td>
			</tr>
			<tr>
				<td height="40px" style="text-align:right">模块描述：&nbsp;</td>
				<td height="68px" colspan="3">
					<textarea id="framework_add_moudledesc" name="descinfo" class="easyui-validatebox" data-options="required:false,validType:['specialCharFilter', 'maxLength[100]']" style="width:87%;height:60px;"></textarea>
				</td>
			</tr>
	  </table>
     </form>
	</div>
	<!--修改用户模块 -->
	<div id="framework_moudle_modify" style="display: none">
	   <form id="framework_moudle_modify_form" method="post">
	     <table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" class="listtable">
			<tr>
				<td height="40px" style="text-align:right"><span style="color:red;font-size:15px">*</span>模块名称：&nbsp;</td>
				<td height="40px">
				    <input id="framework_modify_moudleid" type="hidden" name="moudleid"  />
					<input id="framework_modify_moudlename"  type="text" name="moudlename" class="easyui-validatebox" data-options="required:true,missingMessage:'模块名称必须填写',validType:['specialCharFilter', 'length[1,30]']" panelHeight="auto"/>
				</td>
			</tr>
			<tr>
				<td height="40px" style="text-align:right">模块描述：&nbsp;</td>
				<td height="68px" colspan="3">
					<textarea id="framework_modify_moudledesc" name="descinfo" class="easyui-validatebox" data-options="required:false,validType:['specialCharFilter', 'maxLength[100]']"  style="width:87%;height:60px;"></textarea>
				</td>
			</tr>
	     </table>
      </form>
	</div>
</body>
</html>
